import com.sun.deploy.util.ArrayUtil;
import com.sun.xml.internal.ws.policy.PolicyMapUtil;

import java.lang.reflect.Array;
import java.security.KeyStore;
import java.util.*;
import java.util.stream.Collectors;

public class MapSort implements Comparator<Map.Entry<String, Integer>> {
    public static void main(String[] args) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        hashMap.put("wang", 1);
        hashMap.put("zhang", 4);
        hashMap.put("liu", 3);
        hashMap.put("li", 0);
        Set<Map.Entry<String, Integer>> entries = hashMap.entrySet();
        Map.Entry<String, Integer>[] es = new Map.Entry[entries.size()];
        entries.toArray(es);
        Arrays.sort(es, new MapSort());
        for (Map.Entry<String, Integer> x : es) System.out.println(x);
        LinkedHashSet set = new LinkedHashSet(Arrays.asList(es));
        List<Map.Entry<String, Integer>> entries1 = Arrays.asList(es);
        Arrays.asList(es);
        System.out.println(set);
    }

    @Override
    public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
        return o1.getValue().compareTo(o2.getValue());
    }
}
